package com.itheima.appserver.excepiton;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

@ControllerAdvice
public class MyExHandler {

    @ExceptionHandler(MyEx.class)
    public ResponseEntity myEx(MyEx myEx){
        myEx.printStackTrace();
        //设置响应状态500，及返回错误体
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(myEx.getErroResult());
    }

    @ExceptionHandler(Exception.class)
    public ResponseEntity ex(Exception exception){
        exception.printStackTrace();
        //设置响应状态500，及返回未知异常
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(ErroResult.fail());

    }
}
